//
//  GameDetailTopHeaderView.m
//  gamebox_qpp
//
//  Created by 赵隆杰 on 2022/8/29.
//

#import "GameDetailTopHeaderView.h"

@interface GameDetailTopHeaderView ()

@property (nonatomic, strong) UIScrollView *topScrollView;

@end

@implementation GameDetailTopHeaderView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        
        UIScrollView *topScrollView = [[UIScrollView alloc] init];
        topScrollView.frame = CGRectMake(0, 0, self.width, self.height);
        [self addSubview:topScrollView];
        self.topScrollView = topScrollView;
        
    }
    return self;
}

- (void)refreshData
{
    NSArray *topData = @[@"https://1252153290.vod2.myqcloud.com/da1e24bdvodgzp1252153290/3f45c7f4387702304382691682/lJfsGuQ78ioA.mp4",@"https://pic5.pic3733.com/icon/202208/1072aa3c8f2bfdcd1ddd2a3973308b87.jpg",@"https://pic5.pic3733.com/icon/202208/9719efcfca55463737db63415a8804d7.jpg",@"https://pic5.pic3733.com/icon/202207/b40c4d5aaae44a3ee8db9d6296c266e7.jpg",@"https://pic5.pic3733.com/icon/202207/5e2e4222e42785df1a41a2d8798be485.jpg",@"https://pic5.pic3733.com/icon/202207/334c8af6e5f44635a1ffbde8dc13cde7.jpg"];
    
    [self.topScrollView removeAllSubviews];
    NSString *videoUrl = topData.firstObject;
    CGFloat videoHeight = self.height - 20;
    CGFloat videoWidth = videoHeight * (16.0 / 10.0);
    CGFloat imageLeft = 10;
    if ([videoUrl hasSuffix:@".mp4"]) {
        UIImageView *videoImage = [[UIImageView alloc] init];
        videoImage.layer.cornerRadius = 10;
        videoImage.layer.masksToBounds = YES;
        videoImage.frame = CGRectMake(10, 10, videoWidth, self.height - 20);
        [videoImage yy_setImageWithURL:[NSURL URLWithString:@"https://pic5.pic3733.com/etc/202209/cb46daa4dca50eab7d78ba8d8e0f2a19.jpg"] placeholder:placeholder_image];
        [self.topScrollView addSubview:videoImage];
        imageLeft += CGRectGetMaxX(videoImage.frame);
    }
    CGFloat imageWidth = videoHeight * (9.0 / 16.0);
    UIImageView *lastImage = nil;
    for (NSInteger i = 1; i < topData.count; i++) {
        NSString *imageUrl = topData[i];
        UIImageView *image = [[UIImageView alloc] init];
        image.layer.cornerRadius = 10;
        image.layer.masksToBounds = YES;
        image.frame = CGRectMake(imageLeft + (i - 1) * (imageWidth + 10), 10, imageWidth, videoHeight);
        [image yy_setImageWithURL:[NSURL URLWithString:imageUrl] placeholder:placeholder_image];
        [self.topScrollView addSubview:image];
        lastImage = image;
    }
    self.topScrollView.contentSize = CGSizeMake(CGRectGetMaxX(lastImage.frame) + 10, self.topScrollView.height);
}


+(CGFloat)height
{
    return 200;
}


@end
